package org.icress.fusion.ws

class ReceiveScanJobService {

    static transactional = false

    def getCalloutResponseService    

    def scan() {
        def outBoundInstance = OutBound.withCriteria(uniqueResult:true){
            projections{
                //出站消息ID
                property("id")
            }
            /*
            //执行方式为异步
            eq("asynchronous", true)
            //JOBID不为空，取结果，ID一定不能为空
            isNotNull("jobId")
            //状态为空或者未处理完
            or{
                isNull("jobStatus")
                ne('jobStatus', '2:处理完')
            }
            //错误次数为空，或者未达到限制
            or{
                isNull("retryGetError")
                ltProperty("retryGetError", "retryGetErrorLimit")
            }
            */
            eq('stage', '待处理')
            //根据获取次数排序
            order("priority", "asc")
            order("retryGet", "asc")
            order("id", "asc")
            maxResults(1)
        }
        if(outBoundInstance){
            getCalloutResponseService.fire(outBoundInstance.toLong())
        }
    }
}
